<?xml version="1.0" encoding="utf-8"?>
<ControllerConfig Name="em12">	
<Scripts>	  
	<Script ID="BtnResetSettingsClick">
	 <![CDATA[ 
		[&ResetReg&] = '6f6c6461';
	]]>
	</Script>
	<Script ID="InitConstantValues">
	 <![CDATA[ 
		var mainVal = {&MappingValue&};
				
		{&ObjIndex&} = mainVal & 0xFFFF;
		
		var subIndexHex = (mainVal >> 24 ) & 0xFF;
		{&ObjSubIndex&} = parseInt(subIndexHex, 16);
		
		var sizeHex = (mainVal >> 16 ) & 0xFF;
		{&ObjSize&} =  parseInt(sizesHex, 16);
		
		var addrHex = (mainVal >> 32) & 0xFFFF;
		
		{&ModbusAddr&} = parseInt(addrHex, 16);
	]]>
	</Script>	
	<Script ID="SubindexAndLengthOnInit">
	 <![CDATA[ 	   
		var subIndexStr = {&SubindexAndLength&}.substr(0, 2);		
		var recCountStr = {&SubindexAndLength&}.substr(2, 2);	
		{&Subindex&} = parseInt(subIndexStr, 16);
		{&RecCount&} = parseInt(recCountStr, 16);		
	]]>
	 </Script>  
	 <Script ID="SubindexAndLengthBeforeChange">
		 <![CDATA[ 
			var subIndexStr = {&Subindex&}.toString(16);
			subIndexStr = subIndexStr.length == 1 ? '0' + subIndexStr : subIndexStr; 
			var recCountStr = {&RecCount&}.toString(16);
			recCountStr = recCountStr.length == 1 ? '0' + recCountStr : recCountStr; 		
			{&SubindexAndLength&} = subIndexStr + recCountStr; 		
		]]>
	 </Script>  
	 <Script ID="OnDutyNONCPhaseInit">
		 <![CDATA[ 			
			var uPhaseCode  = ({&UPhaseBit1&}*1).toString() + ({&UPhaseBit2&}*1).toString(); 
			switch (uPhaseCode)
			{
				case '00':
					{&UPhase&} = 0;
					break;
				case '01':
					{&UPhase&} = 1;
					break;
				case '10':
					{&UPhase&} = 2;
					break;					
			}								
		]]>
	 </Script>  
	  <Script ID="OnUPhaseChange">
		 <![CDATA[ 			
			switch({&UPhase&})
			{
				case 0:
				{
					{&UPhaseBit1&} = 0; 
					{&UPhaseBit2&} = 0;
					break;
				}
				case 1:
				{
					{&UPhaseBit1&} = 0;					
					{&UPhaseBit2&} = 1;					
					break;
				}
				case 2:
				{	
					{&UPhaseBit1&} = 1;
					{&UPhaseBit2&} = 0;
					break;
				}
			}							
		]]>
	 </Script>  	
 </Scripts>
</ControllerConfig>
